// 打包并上传，确保服务器已经对本机配置好密钥
const { exec } = require('child_process');
const path = require('path');
const currentDir = path.resolve(__dirname, './');
const buildDir = path.resolve(__dirname, './', 'diet-admin');
const buildCommand = 'npm run build';
const scpCommand = `scp -r "${buildDir}" root@8.134.250.251:/data/nginx/`;

console.log(buildDir)

exec(buildCommand, { cwd: currentDir }, (error,
  
  stdout, stderr) => {
  if (error) {
    return console.error(`执行错误: ${error}`);
  }
  if (stderr) {
    console.error(`标准错误: ${stderr}`);
  }
  console.log(stdout + 'build success');

  exec(scpCommand, (error, stdout, stderr) => {
    if (error) {
      console.error(`执行错误: ${error}`);
      return;
    }
    if (stderr) {
      console.error(`标准错误: ${stderr}`);
    }
    console.log(stdout + 'scp success');
  });

});